﻿using AspectCore.DynamicProxy;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using RTW.Core.Extensions;
using RTW.Models;
using RTW.Servers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RTW.Web.Component
{
    public class DpetOrgList : ViewComponent
    {
        TOrganizationServer organizationServer;
        private IMemoryCache _memoryCache;
        private string cacheKey = "DepartmentOrg";


        public DpetOrgList(IMemoryCache memoryCache)
        {
          //  _departmentServer = new DepartmentServer();
           organizationServer = new TOrganizationServer();
            _memoryCache = memoryCache;
        }

        public async Task<IViewComponentResult> InvokeAsync(string DMID)
        {
            //string DMID = Request.Query["DMID"];
            var items = new List<TOrganization>();
            //if (!_memoryCache.TryGetValue(cacheKey, out items))
            //{
            //    items = await organizationServer.GetAsync(m=>m.DMID== DMID);
            //}
            //if (items?.Count == 0)
            //{
                items = await organizationServer.GetAsync(m => m.DMID == DMID);
            //}           
            //_memoryCache.Set(cacheKey, items, TimeSpan.FromMinutes(10));
            return View(items);
        }


    }




}
